package com.yanqu.road.server.cmd.activity.drawPictures;

import com.yanqu.road.entity.activity.drawPictures.DrawPicturesResult;
import com.yanqu.road.pb.drawPicturesActivity.DrawPicturesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.drawPictures.DrawPicturesActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_DRAW_PICTURES_DRAW, desc = "绘制年画")
public class DrawPicturesDrawCmd extends AbstractCommand {
    private int activityId;
    private int type;
    private DrawPicturesResult result;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DrawPicturesProto.DrawPicturesDrawReqMsg msg = DrawPicturesProto.DrawPicturesDrawReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        result = player.getModule(DrawPicturesActivityModule.class).draw(activityId, type);
    }

    @Override
    public void sendData(GamePlayer player) {
        DrawPicturesProto.DrawPicturesDrawRespMsg.Builder respMsg = DrawPicturesProto.DrawPicturesDrawRespMsg.newBuilder();
        respMsg.setRet(result.getRet());
        if (result.getRet() == 0) {
            respMsg.setAddIntegral(result.getAddIntegral());
            respMsg.addAllPicturesId(result.getDrawPicturesIdList());
        }
        player.sendPacket(ClientProtocol.U_ACTIVITY_DRAW_PICTURES_DRAW, respMsg);
    }
}
